# tap.chooseMedia(Object object)
以 Promise 风格调用:支持
# 功能描述
从相机拍摄或从本地相册中选择图片或视频。
# 参数
# Object object
属性 | 类型 | 默认值 | 必填 | 说明 | |||||||||
count | number | 9 | 否 | 最多可支持20个文件 | |||||||||
mediaType | Array.<string> | ['image', 'video'] | 否 | 文件类型 | |||||||||
| |||||||||||||
sourceType | Array.<string> | ['album', 'camera'] | 否 | 图片和视频选择的来源 | |||||||||
| |||||||||||||
maxDuration | number | 10 | 否 | 拍摄视频最长拍摄时间,单位秒。时间范围为 3s 至 60s 之间。不限制相册。安卓不支持该参数,设置无效 | |||||||||
sizeType | Array.<string> | ['compressed'] | 否 | 是否压缩所选文件, iOS对所有mediaType生效 不支持original,设置任何值只返回压缩过的图片和视频 | |||||||||
camera | string | 'back' | 否 | 仅在 sourceType 为 camera 时生效,使用前置或后置摄像头。安卓只支持back,设置front无效 | |||||||||
| |||||||||||||
success | function | 否 | 接口调用成功的回调函数 | ||||||||||
fail | function | 否 | 接口调用失败的回调函数 | ||||||||||
complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
# object.success 回调函数
# 参数
# Object res
属性 | 类型 | 说明 | |||||||||||||||||||||||||||||||||||||||||||
tempFiles | Array.<Object> | 本地临时文件列表 | |||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||
type | string | 文件类型,有效值有 image 、video、mix |
# 示例代码
tap.chooseMedia({
count: 9,
mediaType: ['image','video'],
sourceType: ['album', 'camera'],
maxDuration: 30,
camera: 'back',
success(res) {
console.log(res.tempFiles[0].tempFilePath)
console.log(res.tempFiles[0].size)
}
})